package com.jibei.mendo.utils;

import android.content.Context;
import android.os.Vibrator;

import static android.content.Context.VIBRATOR_SERVICE;

/**
 * Created by lhl on 2019/8/17.
 * 蜂鸣器工具类
 */
public class VibratorUtil {

    private VibratorUtil() {
    }

    public static VibratorUtil getInstance() {
        return VibratorUtil.Holder.instance;
    }

    private static class Holder {
        private static final VibratorUtil instance = new VibratorUtil();
    }


    /**
     * 自定义蜂鸣:只响一次，设定蜂鸣时间
     */
    public void executeVibrator(Context mContext, long milliseconds) {
        Vibrator vibrator = (Vibrator) mContext.getSystemService(VIBRATOR_SERVICE);
        //只响一次，设定蜂鸣时间
        vibrator.vibrate(milliseconds);
    }

    /**
     * 自定义蜂鸣:每两个数为一组表示间隔时间和蜂鸣时间，并自己设定是否循环和循环次数
     */
    public void executeVibrator(Context mContext, long[] pattern) {
        Vibrator vibrator = (Vibrator) mContext.getSystemService(VIBRATOR_SERVICE);
        //                long[] pattern = {10000, 1000, 2000, 1000};//过10秒响1秒--->过2秒响1秒--->完。
        vibrator.vibrate(pattern, -1);
    }
}
